From 627aaffcb5190c363dcae01b2a095815cdbe4ecc Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Tue, 17 May 2005 22:29:19 +0000 Subject: [PATCH] bitkeeper revision 1.1440 (428a703fGt3asjVc5fTAW72ClnFOog) Many files: g/c _readline{,s} and use regular readline{,s} functions -- the special _readline{,s} functions were only needed because of Twisted. ip.py: Also use readlines() instead of xreadlines(). Signed-off-by: Christian Limpach --- tools/python/xen/sv/Daemon.py | 4 +-- tools/python/xen/util/blkif.py | 4 +-- tools/python/xen/util/ip.py | 38 +++-------------------- tools/python/xen/xend/Blkctl.py | 2 -- tools/python/xen/xend/XendDomainInfo.py | 1 - tools/python/xen/xend/encode.py | 4 +-- tools/python/xen/xend/server/SrvDaemon.py | 4 +-- tools/python/xen/xend/sxp.py | 3 +- 8 files changed, 9 insertions(+), 51 deletions(-) diff --git a/tools/python/xen/sv/Daemon.py b/tools/python/xen/sv/Daemon.py index 5a8d18e5e4..510cfa9f04 100644 --- a/tools/python/xen/sv/Daemon.py +++ b/tools/python/xen/sv/Daemon.py @@ -15,8 +15,6 @@ from xen.sv.params import * from twisted.internet import reactor from twisted.web import static, server, script -from xen.util.ip import _readline, _readlines - class Daemon: """The xend daemon. """ @@ -59,7 +57,7 @@ class Daemon: return 0 # Read the pid of the previous invocation and search active process list. pid = open(PID_FILE, 'r').read() - lines = _readlines(os.popen('ps ' + pid + ' 2>/dev/null')) + lines = os.popen('ps ' + pid + ' 2>/dev/null').readlines() for line in lines: if re.search('^ *' + pid + '.+xensv', line): if not kill: diff --git a/tools/python/xen/util/blkif.py b/tools/python/xen/util/blkif.py index 21c9202788..0caf03b5cf 100644 --- a/tools/python/xen/util/blkif.py +++ b/tools/python/xen/util/blkif.py @@ -4,8 +4,6 @@ import string from xen.xend.XendLogging import log -from xen.util.ip import _readline, _readlines - def expand_dev_name(name): if not name: return name @@ -71,7 +69,7 @@ def blkdev_uname_to_file(uname): def mount_mode(name): mode = None name = expand_dev_name(name) - lines = _readlines(os.popen('mount 2>/dev/null')) + lines = os.popen('mount 2>/dev/null').readlines() exp = re.compile('^' + name + ' .*[\(,]r(?P[ow])[,\)]') for line in lines: pm = exp.match(line) diff --git a/tools/python/xen/util/ip.py b/tools/python/xen/util/ip.py index 2ce0b41394..9133e886f2 100644 --- a/tools/python/xen/util/ip.py +++ b/tools/python/xen/util/ip.py @@ -4,41 +4,11 @@ import socket import struct import errno -def _readlines(fd): - """Version of readlines safe against EINTR. - """ - import errno - - lines = [] - while 1: - try: - line = fd.readline() - except IOError, ex: - if ex.errno == errno.EINTR: - continue - else: - raise - if line == '': break - lines.append(line) - return lines - -def _readline(fd): - """Version of readline safe against EINTR. - """ - while 1: - try: - return fd.readline() - except IOError, ex: - if ex.errno == errno.EINTR: - continue - else: - raise - ##### Networking-related functions def get_defaultroute(): fd = os.popen('/sbin/ip route list 2>/dev/null') - for line in fd.xreadlines(): + for line in fd.readlines(): m = re.search('^default via ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) dev ([^ ]*)', line) if m: @@ -57,7 +27,7 @@ def get_current_ipaddr(dev='defaultroute'): if not dev: return fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' ) - for line in fd.xreadlines(): + for line in fd.readlines(): m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*', line ) if m: @@ -76,7 +46,7 @@ def get_current_ipmask(dev='defaultroute'): if not dev: return fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' ) - for line in fd.xreadlines(): + for line in fd.readlines(): m = re.search( '^.+Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*', line ) if m: @@ -95,7 +65,7 @@ def get_current_ipgw(dev='defaultroute'): if not dev: return fd = os.popen( '/sbin/route -n' ) - for line in fd.xreadlines(): + for line in fd.readlines(): m = re.search( '^\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' + '\s+\S+\s+\S*G.*' + dev + '.*', line ) if m: diff --git a/tools/python/xen/xend/Blkctl.py b/tools/python/xen/xend/Blkctl.py index 0b46f54079..44a4b49803 100644 --- a/tools/python/xen/xend/Blkctl.py +++ b/tools/python/xen/xend/Blkctl.py @@ -8,8 +8,6 @@ import xen.util.process from xen.xend import XendRoot -from xen.util.ip import _readline, _readlines - xroot = XendRoot.instance() """Where network control scripts live.""" diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 334a154460..e0aae81944 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -14,7 +14,6 @@ import time import xen.lowlevel.xc; xc = xen.lowlevel.xc.new() import xen.util.ip -from xen.util.ip import _readline, _readlines from xen.xend.server import channel, controller from xen.util.blkif import blkdev_uname_to_file diff --git a/tools/python/xen/xend/encode.py b/tools/python/xen/xend/encode.py index 48815defa9..38c9351db7 100644 --- a/tools/python/xen/xend/encode.py +++ b/tools/python/xen/xend/encode.py @@ -14,8 +14,6 @@ import httplib import random import md5 -from xen.util.ip import _readline, _readlines - # Extract from HTML4 spec. ## The following example illustrates "multipart/form-data" ## encoding. Suppose we have the following form: @@ -124,7 +122,7 @@ def encode_multipart(d): out.write('"\r\n') out.write('Content-Type: application/octet-stream\r\n') out.write('\r\n') - for l in _readlines(v): + for l in v.readlines(): out.write(l) else: out.write('Content-Disposition: form-data; name="') diff --git a/tools/python/xen/xend/server/SrvDaemon.py b/tools/python/xen/xend/server/SrvDaemon.py index 3709f17edd..61a0e33949 100644 --- a/tools/python/xen/xend/server/SrvDaemon.py +++ b/tools/python/xen/xend/server/SrvDaemon.py @@ -27,8 +27,6 @@ from xen.xend.server import SrvServer from xen.xend import XendRoot from xen.xend.XendLogging import log -from xen.util.ip import _readline, _readlines - import channel import controller import event @@ -99,7 +97,7 @@ class Daemon: """ running = 0 if pid: - lines = _readlines(os.popen('ps %d 2>/dev/null' % pid)) + lines = os.popen('ps %d 2>/dev/null' % pid).readlines() exp = '^ *%d.+%s' % (pid, name) for line in lines: if re.search(exp, line): diff --git a/tools/python/xen/xend/sxp.py b/tools/python/xen/xend/sxp.py index e2c0de5c5b..f1de3619d5 100644 --- a/tools/python/xen/xend/sxp.py +++ b/tools/python/xen/xend/sxp.py @@ -17,7 +17,6 @@ import types import errno import string from StringIO import StringIO -from xen.util.ip import _readline, _readlines __all__ = [ "mime_type", @@ -714,7 +713,7 @@ def parse(io): """ pin = Parser() while 1: - buf = _readline(io) + buf = io.readline() pin.input(buf) if len(buf) == 0: break -- 2.30.2